package com.thinkgsp.jxc.model;

import java.math.BigDecimal;
import java.sql.Date;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * 应收应付核销日志
 * @author evan
 *
 */
public class RpBillCheckLog extends BaseModel {
	
	/**
	 * 核销类型: 收款单核销
	 */
	public final static int CHECK_TYPE_RECBILL = 1;
	
	/**
	 * 核销类型: 收款单退款核销
	 */
	public final static int CHECK_TYPE_REFUND_RECBILL = 2;
	
	/**
	 * 核销类型: 应收款冲应付款
	 */
	public final static int CHECK_TYPE_ARECBILL_OFFSET_APAYBILL = 3;
	
	/**
	 * 核销类型: 应收款转销
	 */
	public final static int CHECK_TYPE_ARECBILL_TRANSFER = 4;
	
	/**
	 * 核销类型: 付款单核销
	 */
	public final static int CHECK_TYPE_PAYBILL = -1;
	
	/**
	 * 核销类型: 付款单退款核销
	 */
	public final static int CHECK_TYPE_REFUND_PAYBILL = -2;
	
	/**
	 * 核销类型: 应付款冲应收款
	 */
	public final static int CHECK_TYPE_APAYBILL_OFFSET_ARECBILL = -3;
	
	/**
	 * 核销类型: 应付款转销
	 */
	public final static int CHECK_TYPE_APAYBILL_TRANSFER = -4;

	private static final long serialVersionUID = 7603663660878261192L;

	private Long id;
	private Long checkId;
	private Date checkDate = new Date(System.currentTimeMillis());
	private Integer checkerId;
	private Integer custSuppId;
	private Integer deptId;
	private Long contactId;
	private Integer checkType;
	private Integer direct;
//	private BigDecimal debitAmt;
//	private BigDecimal creditAmt;
	private Integer fyear;
	private Integer period;
	private String remark;
	private BigDecimal checkAmount;
	
	private Emp checker;
	private Customer customer;
	private RpContact contact;
	
	/**
	 * 核销金额
	 * @return
	 */
	public BigDecimal getCheckAmount() {
		return checkAmount;
	}

	public void setCheckAmount(BigDecimal checkAmount) {
		this.checkAmount = checkAmount;
	}

	/**
	 * 核销人
	 * @return
	 */
	public Emp getChecker() {
		return checker;
	}

	public void setChecker(Emp checker) {
		this.checker = checker;
	}

	/**
	 * 客户
	 * @return
	 */
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * 往来明细
	 * @return
	 */
	public RpContact getContact() {
		return contact;
	}

	public void setContact(RpContact contact) {
		this.contact = contact;
	}

	public Integer getFyear() {
		return fyear;
	}

	public void setFyear(Integer fyear) {
		this.fyear = fyear;
	}

	public Integer getPeriod() {
		return period;
	}

	public void setPeriod(Integer period) {
		this.period = period;
	}

	/**
	 * 表Id
	 * @return
	 */
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 核销Id
	 * @return
	 */
	public Long getCheckId() {
		return checkId;
	}

	public void setCheckId(Long checkId) {
		this.checkId = checkId;
	}

	/**
	 * 核销日期
	 * @return
	 */
	public Date getCheckDate() {
		return checkDate;
	}

	public void setCheckDate(Date checkDate) {
		this.checkDate = checkDate;
	}

	/**
	 * 核销人
	 * @return
	 */
	public Integer getCheckerId() {
		return checkerId;
	}

	public void setCheckerId(Integer checkerId) {
		this.checkerId = checkerId;
	}

	/**
	 * 客户
	 * @return
	 */
	public Integer getCustSuppId() {
		return custSuppId;
	}

	public void setCustSuppId(Integer custSuppId) {
		this.custSuppId = custSuppId;
	}

	/**
	 * 往来明细Id
	 * @return
	 */
	public Long getContactId() {
		return contactId;
	}

	public void setContactId(Long contactId) {
		this.contactId = contactId;
	}

	/**
	 * 核销类型: 1收款单核销；2收款单退款核销；3应收款冲应付款；4应收款转销；
	 *       -1付款单核销；-2付款单退款核销；-3应付款冲应收款；-4应付款转销
	 * @return
	 */
	public Integer getCheckType() {
		return checkType;
	}

	public void setCheckType(Integer checkType) {
		this.checkType = checkType;
	}
	/**
	 * 核销类型名称
	 * @return
	 */
	public String getCheckTypeName() {
		String name = "";
		switch(checkType) {
		case 1:
			name = "收款单核销";
			break;
		case 2:
			name = "收款单退款核销";
			break;
		case 3:
			name = "应收款冲应付款";
			break;
		case 4:
			name = "应收款转销";
			break;
		case -1:
			name = "付款单核销";
			break;
		case -2:
			name = "付款单退款核销";
			break;
		case -3:
			name = "应付款冲应收款";
			break;
		case -4:
			name = "应付款转销";
			break;
		}
		return name;
	}

	/**
	 * 方向
	 * @return
	 */
	public Integer getDirect() {
		return direct;
	}

	public void setDirect(Integer direct) {
		this.direct = direct;
	}

	/**
	 * 借方金额
	 * @return
	 */
	public BigDecimal getDebitAmt() {
		//return debitAmt;
		if(contact.getArpBillId() != null) {
			return checkAmount;
		}
		return null;
	}

//	public void setDebitAmt(BigDecimal debitAmt) {
//		this.debitAmt = debitAmt;
//	}

	/**
	 * 贷方金额
	 * @return
	 */
	public BigDecimal getCreditAmt() {
		//return creditAmt;
		if(contact.getRpBillId() != null) {
			return checkAmount;
		}
		return null;
	}

//	public void setCreditAmt(BigDecimal creditAmt) {
//		this.creditAmt = creditAmt;
//	}

	/**
	 * 备注
	 * @return
	 */
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	/**
	 * 获取应收应付单编号
	 * @return
	 */
	public String getArpBillCode() {
		if(contact.getArpBillId() != null) {
			return contact.getBillCode();
		}
		return null;
	}
	
	/**
	 * 获取收付款单编号
	 * @return
	 */
	public String getRpBillCode() {
		if(contact.getRpBillId() != null) {
			return contact.getBillCode();
		}
		return null;
	}
	
	/**
	 * @return the deptId
	 */
	public Integer getDeptId() {
		return deptId;
	}

	/**
	 * @param deptId the deptId to set
	 */
	public void setDeptId(Integer deptId) {
		this.deptId = deptId;
	}

	/**
	 * 获取转销单编号
	 * @return
	 */
	public String getTransferBillCode() {
		if(Math.abs(this.checkType) == 4) {
			return contact.getBillCode();
		}
		return null;
	}
	
	public String getTransferCust() {
		if(Math.abs(checkType) == 4) {
			return  "[" + customer.getCustomerCode() + "]" + 
					customer.getCustomerName();
		}
		return null;
	}

	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE);
		sb.append("id",this.id)
		  .append("checkId",this.checkId)
		  .append("custSuppId",this.custSuppId);
		
		return sb.toString();
	}

	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}
		if(!(o instanceof RpBillCheckLog)) {
			return false;
		}
		final RpBillCheckLog check = (RpBillCheckLog)o;
		if(id != null) {
			return id.equals(check.getId());
		} else {
			return check.getId() == null;
		}
	}

	@Override
	public int hashCode() {
		return (this.id != null ? this.id.hashCode() : 0);
	}

}
